|
Cytosim
PI
Cytoskeleton Simulator
|
The generation of random bits is done with Mersenne Twister from U. of Hiroshima
http://en.wikipedia.org/wiki/Mersenne_twister http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html
Public Member Functions | |
| Random () | |
| Constructor. | |
| ~Random () | |
| destructor | |
| void | seed (const uint32_t s) |
| seed with integer | |
| uint32_t | seedTimer () |
| seed with time() | |
| uint32_t | pint () |
| unsigned integer in [0,2^32-1] | |
| uint32_t | pint_exc (const uint32_t n) |
| unsigned integer in [0,n-1] for n < 2^32 | |
| uint32_t | pint_inc (const uint32_t n) |
| unsigned integer in [0,n] for n < 2^32 | |
| uint32_t | pint_inc2 (const uint32_t n) |
| integer in [0,n] for n < 2^32, (slow) integer based algorithm More... | |
| int32_t | sint () |
| signed integer in [-2^31+1,2^31-1]; inlined for speed | |
| int32_t | sint_inc (const int32_t n) |
| integer in [-N, N], boundaries included | |
| int32_t | sint_exc (const int32_t n) |
| integer in [1-N, N-1], i.e. in ]-N,N[ with boundaries excluded | |
| int32_t | int_range (const int32_t low, const int32_t high) |
| random integer in [low, high] ( = low + pint_inc(high-low) ) | |
| uint32_t | pint_ratio (uint32_t n, const int ratio[]) |
| integer in [0 N], with probabilities given in ratio[] of size N, with sum(ratio)>0 More... | |
| uint32_t | poisson (real E) |
| integer k of probability distribution p(k,E) = exp(-E) * pow(E,k) / factorial(k) More... | |
| uint32_t | poissonE (real EL) |
| integer k of probability distribution p(k,E) = EL * pow(E,k) / factorial(k) More... | |
| uint32_t | geometric (real p) |
| number of successive unsuccessful trials, when success has probability p (result >= 0) | |
| uint32_t | binomial (int n, real p) |
| number of sucesses among n trials of probability p | |
| bool | test (real const &p) |
| true with probability (p), false with probability (1-p) | |
| bool | test_not (real const &p) |
| true with probability (1-p), false with probability (p) | |
| bool | test_uint (uint32_t p) |
| true with probability p / 2^32 | |
| bool | flip () |
| true or false with equal chance | |
| int | sflip () |
| returns -1 or 1 with equal chance | |
| int | sign_exc (const real a) |
| this sign-function returns -1 or +1 randomly, if the argument is 0 | |
| real | preal () |
| positive real number in [0,1[, zero included | |
| real | sreal () |
| positive real number in [0,n[ = n * preal() : deprecated, use preal() * n More... | |
| real | preal_exc () |
| non-zero real number in ]0,1[ | |
| real | preal_exc (real n) |
| non-zero real number in ]0,n[ | |
| real | real_range (real a, real b) |
| real number uniformly in [a,b] | |
| real | gauss () |
| random Gaussian number, following a normal law N(0,1) More... | |
| void | gauss_pair (real &, real &) |
| set two number, following a normal law N(0,1) More... | |
| void | gauss_array (unsigned int n, real vec[]) |
| fill array vec with normal law N(0,1). More... | |
| real | gauss_slow () |
| signed real number, following a normal law N(0,1), slower algorithm More... | |
| real | exponential () |
| positive real x, according to distribution P(x) = exp(-x), expectancy = 1.0 | |
| real | exponential (const real E) |
| positive real x, with distribution P(x) = exp(-x/E) / E : [ E = 1/Rate ] | |
| template<typename T > | |
| T | choice (const T &x, const T &y) |
| uniform choice among the 2 values given: x,y | |
| template<typename T > | |
| T | choice (const T &x, const T &y, const T &z) |
| template<typename T > | |
| T | choice (const T val[], int size) |
| template<typename T > | |
| void | mix (T val[], int size) |
| uniform shuffling of array T[]. More... | |
| real gauss | ( | ) |
Signed real number, following a normal law N(0,1) using the polar rejection method (see Numerical Recipe)
| void gauss_array | ( | unsigned int | n, |
| real | vec[] | ||
| ) |
Fill n values in array vec[] with Gaussian ~ N(0,1).
Signed real number, following a normal law N(0,1) using the polar rejection method (see Numerical Recipe)
| real gauss_slow | ( | ) |
this version uses cos() and sin() and is slower than gauss(). const real PI = 3.14159265358979323846264338327950288;
|
inline |
Algorithm from knuth's The Art of Programming, Vol 2 chp. 3.4.2
| uint32_t pint_inc2 | ( | const uint32_t | n | ) |
integer in [0,n] for n < 2^32
| uint32_t pint_ratio | ( | uint32_t | n, |
| const int | ratio[] | ||
| ) |
returns an integer in [0 n], with the ratios given in the array of ints
| uint32_t poisson | ( | real | E | ) |
expectation=E variance=E http://en.wikipedia.org/wiki/Poisson_distribution
This routine is very slow for large values of E. If E > 1000, the Poisson distribution can be approximate by a Gaussian distribution Poisson(E) ~ Gauss(E, E)
| uint32_t poissonE | ( | real | EL | ) |
This is equivalent to calling poisson(exp(-E)) The argument is EL = exp(-E) expectation=E variance=E (see wikipedia, Poisson Distribution)
|
inline |
signed real number in ]-1,1[, boundaries excluded